<template>
  <a-card :bordered="false" class="card-area">
    <div class="table-page-search-wrapper">
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :sm="{span:24}" :lg="{span:6}">
            <a-form-item label="院系">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zsyxm" @change="yxChange">
                <a-select-option v-for="i in selectMenu.yx" :key="i.id" :value="i.dwh">{{ i.dwh+'-'+i.dwmc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col ::sm="{span:24}" :lg="{span:6}">
            <a-form-item label="招生年度">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zsnj">
                <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:24}" :lg="{span:6}" style="padding-top: 29px;">
            <a-button type="primary" @click="loadData">查询</a-button>
              <a-button type="primary" @click="exportExcel">导出</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <a-table
      ref="table"
      size="default"
      rowKey="key"
      :columns="columns"
      :loading="loading"
      :dataSource="newData"
      :alert="options.alert"
      :rowSelection="options.rowSelection"
      :pagination="false"
    >
      <span slot="serial" slot-scope="text, record, index">
        {{ index + 1 }}
      </span>
    </a-table>
  </a-card>
</template>

<script>
// import moment from 'moment'
import { STable } from '~'
import { mapState } from 'vuex'

const selectArr = [ 'TYPE0126']
export default {
  name: 'Admissionstat',
  components: {
    STable
  },
  data () {
    return {
      loading: false,
      data: [],
      newData: [],
      // 查询参数
      queryParam: {
        zsyxm:'',
        zsnj:''
      },
      postParams: {},
      // 表头
      columns: [ 
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' },
          customRender: (value, row, index) => {
              console.log(value, row, index)
              const obj = {
                  children: row.xh,
                  attrs: {},
              };
              if (row.seq >= 1) {   // 第一行数据开始，跨行合并的长度为数据data的长度
                  obj.attrs.rowSpan = row.len;
              }
              if (row.seq >= 2 ) {   // 从第一行往后的所有行表格均合并
                  obj.attrs.rowSpan = 0;

              }
              return obj;
          }
        },
        {
          title: '院系代码',
          dataIndex: 'zsyxm'
        },
        {
          title: '院系',
          dataIndex: 'dwmc'
        },
        {
          title: '专业代码',
          dataIndex: 'zszym'
        },
        {
          title: '专业',
          dataIndex: 'zymc'
        },
        {
          title: '计划人数',
          dataIndex: 'zszjhrs'
        },
        {
          title: '录取人数',
          dataIndex: 'zsyfpzrs'
        },
        {
          title: '非专业计划数',
          dataIndex: 'fzyxwjhrs'
        },
        {
          title: '非专业录取数',
          dataIndex: 'fzyxwyfprs'
        },
        {
          title: '专业计划数',
          dataIndex: 'zyxwjhrs'
        },
        {
          title: '专业录取数',
          dataIndex: 'zyxwyfprs'
        }
      ],

      // custom table alert & rowSelection
      options: {
        alert: { show: false }
      },
      visible: false,
      confirmLoading: false,
      editId: null,
      selectMenu: {
        yx: [], // 院系
        zy: [] // 所属专业
      }
    }
  },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0126: state => state.app['TYPE0126'] // 年级
    })
  },
  created () {
    this.initSelectMenu()
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yx: res[0].data
        }
          this.queryParam.zsyxm=res[0].data[0].dwh;
        	this.$api.base.majorAll({lsdwh: this.queryParam.zsyxm}).then(res => {
       				 this.$set(this.selectMenu, 'zy', res.data)
					  })
					this.$api.base.getSchoolYear().then(res=>{
					this.queryParam.zsnj=res.data.doctoralAdmissionYear;
					this.loadData({
					pageNum:1,
					pageSize:10
					})
     				})
      })
    },
  loadData(parameter = {}) {
    if(!parameter.pageNum){
         this.pagination.current = 1
         parameter.pageNum = 1
       }
      let params = Object.assign(this.queryParam, parameter)
      this.loading = true;
      this.$api.doctorRecruit.cencusList(params).then(res => {
        // console.log(res)
         const pagination = { ...this.pagination
        };
        pagination.total = 0
        if (res.data && res.data.total) {
          pagination.total = res.data.total;
        }
        this.data = []
        this.newData = []
        this.pagination = pagination;
        if (res.data && res.data.length) {
          this.data = res.data;
          this.data.map((item,index) => {
            item.map((it,ind) => {
              it.len = item.length
              it.seq = ind + 1
              it.xh = index + 1
              console.log(it.seq)
              this.newData = this.newData.concat(it)
            })
          })
          console.log(this.newData)
        }
        this.loading = false;
      })
    },
    // 选择院系
    yxChange (code) {
    },
    // 选择招生年度
    zsndChange () {
    },
    // 导出
    exportExcel () {
      console.log('导出')
      this.$export('admissions/bszsjh/lqrstjExport',this.queryParam)
    }
  }
}
</script>
